//
//  ShuangSeVC.m
//  K8彩票
//
//  Created by zyn on 2017/6/8.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "ShuangSeVC.h"
#import "BallButton.h"

@interface ShuangSeVC ()<OnClickBallCallback>{
    NSMutableArray *arrayRedDatas, *arrayBlueDatas;
    NSMutableArray *arrayRed21Datas, *arrayRed22Datas,*arrayBlue2Datas;
}

@property (weak, nonatomic) IBOutlet UIButton *btnSelectTop; // 顶部选择玩法按钮
@property (weak, nonatomic) IBOutlet UIView *viewType1; // 普通玩法容器
@property (weak, nonatomic) IBOutlet UIView *viewType2; // 胆拖玩法容器
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType1Height;
@property (weak, nonatomic) IBOutlet UIView *viewType1Red;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType1RedHeight;
@property (weak, nonatomic) IBOutlet UIView *viewType1Blue;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType1BlueHeight;


/////////////////////////胆拖///////////////////////////////////////
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType2Height;
@property (weak, nonatomic) IBOutlet UIView *viewType2Red2;
@property (weak, nonatomic) IBOutlet UIView *viewType2Red1;
@property (weak, nonatomic) IBOutlet UIView *viewType2Blue;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType2Red1Height;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType2Red2Height;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType2BlueHeight;




@property (weak, nonatomic) IBOutlet UILabel *labelMoney;
@property (weak, nonatomic) IBOutlet UIButton *btnApply;



@end

@implementation ShuangSeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeView];
    [self initializeData];
}

-(void)initializeView{
    _viewType1.hidden = NO;
    _viewType2.hidden = YES;
    
    isApplay = NO;
    ((ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController).mainTabbar.frame = CGRectMake(0, -49, 0, 0);
    
    _btnApply.layer.cornerRadius = 4;

    _btnSelectTop.tag = 0;
    _btnSelectTop.layer.borderColor = [[UIColor whiteColor]CGColor];
    _btnSelectTop.layer.borderWidth = 1;
    _btnSelectTop.layer.cornerRadius = 4;
    _btnSelectTop.layer.masksToBounds = YES;
    [_btnSelectTop addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
    
    _layoutViewType1RedHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6;
    _layoutViewType1BlueHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 3 + 12 * 4;
    _layoutViewType1Height.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6 + (ScreenWidth()  - 8 * 12) / 7 * 3 + 12 * 4;
    
    _layoutViewType2Red1Height.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6;
    _layoutViewType2Red2Height.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6;
    _layoutViewType2BlueHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 3 + 12 * 4;
    _layoutViewType1Height.constant = ((ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6) * 2 + (ScreenWidth()  - 8 * 12) / 7 * 3 + 12 * 4 + 80;



    
   
}

-(void)initializeData{
    arrayRedDatas = [NSMutableArray arrayWithCapacity:0];
    arrayBlueDatas = [NSMutableArray arrayWithCapacity:0];
    arrayRed21Datas = [NSMutableArray arrayWithCapacity:0];
    arrayRed22Datas = [NSMutableArray arrayWithCapacity:0];
    arrayBlue2Datas = [NSMutableArray arrayWithCapacity:0];
    
    // 普通
    for (int i = 1; i < 34; i ++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:RED_BALL];
        btn.callback = self;
        [_viewType1Red addSubview:btn];
        [arrayRedDatas addObject:btn];
    }
    
    for (int i = 1; i < 17; i++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:BLUE_BALL];
        btn.callback = self;
        [_viewType1Blue addSubview:btn];
        [arrayBlueDatas addObject:btn];
    }
    
    // 胆拖
    for (int i = 1; i < 34; i ++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:RED_BALL];
        btn.callback = self;
        [_viewType2Red1 addSubview:btn];
        [arrayRed21Datas addObject:btn];
    }
    for (int i = 1; i < 34; i ++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:RED_BALL];
        btn.callback = self;
        [_viewType2Red2 addSubview:btn];
        [arrayRed22Datas addObject:btn];
    }
    
    for (int i = 1; i < 17; i++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:BLUE_BALL];
        btn.callback = self;
        [_viewType2Blue addSubview:btn];
        [arrayBlue2Datas addObject:btn];
    }

}

- (IBAction)onClickBack:(id)sender {
    [self back];
}

- (IBAction)onClickApply:(id)sender {
//    if (isApplay) {
//        [self showHint:@"下注成功"];
//    }else{
//        [self showHint:@"抱歉，请先下注"];
//    }
    if (IS_OPEN_SWITCH) {
        [self showHint:NSLocalizedString(@"投注成功", @"投注成功")];

    }
    else
    {
        [self showHint:NSLocalizedString(@"请开启虚拟投注功能", @"请开启虚拟投注功能")];
    }
}

-(void)onClick:(UIButton *)btn{
    switch (btn.tag) {
        case 0:
            // 选择玩法
            [self selectPlayType];
            break;
            
        default:
            break;
    }
}

/// 弹出选择玩法选择框
-(void)selectPlayType{
    UIAlertController*alertController = [[UIAlertController alloc] init];
    UIAlertAction*alertAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"取消", @"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];
    [alertController addAction:alertAction];
    
    [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"普通投注", @"普通投注") style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *  action) {
        [_btnSelectTop setTitle:NSLocalizedString(@"双色球", @"双色球") forState:UIControlStateNormal];
        _viewType1.hidden = NO;
        _viewType2.hidden = YES;
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"胆拖投注", @"胆拖投注") style:UIAlertActionStyleDefault handler:^(UIAlertAction *  action) {
        [_btnSelectTop setTitle:NSLocalizedString(@"双色球胆拖", @"双色球胆拖") forState:UIControlStateNormal];
        _viewType1.hidden = YES;
        _viewType2.hidden = NO;
    }]];
    [self presentViewController:alertController animated:YES completion:nil];

}


-(void)onClickBall{
//    int red = 0;
//    int blue = 0;
//    for (BallButton *btn in arrayRedDatas) {
//        if (btn.isSelect)
//            red++;
//    }
//    
//    for (BallButton *btn in arrayBlueDatas) {
//        if (btn.isSelect)
//            blue++;
//    }
//    
//    if (red > 5 && blue > 0) {
//        _labelMoney.text = @"共1注 2元";
//        isApplay = YES;
//    }else{
//        _labelMoney.text = @"共0注 0元";
//        isApplay = NO;
//    }
}



@end
